package com.eduhzy.ttw.clazz.di.module;

import android.content.res.ColorStateList;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.clazz.R;
import com.eduhzy.ttw.clazz.mvp.contract.ClazzReportContract;
import com.eduhzy.ttw.clazz.mvp.model.ClazzReportModel;
import com.eduhzy.ttw.clazz.mvp.model.entity.ClazzReportList;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.ActivityScope;
import com.qmuiteam.qmui.util.QMUIViewHelper;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButtonDrawable;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-7 10:35:33
 */
@Module
public class ClazzReportModule {
    private ClazzReportContract.View view;

    /**
     * 构建ClazzReportModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public ClazzReportModule(ClazzReportContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    ClazzReportContract.View provideClazzReportView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    ClazzReportContract.Model provideClazzReportModel(ClazzReportModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    List<ClazzReportList> provideLists() {
        return new ArrayList<>();
    }


    @ActivityScope
    @Provides
    RecyclerView.LayoutManager provideLayoutDeleteManager() {
        return new LinearLayoutManager(view.getActivity());
    }


    @ActivityScope
    @Provides
    BaseQuickAdapter<ClazzReportList, AutoBaseViewHolder> providerDeleteAdapter(List<ClazzReportList> lists) {
        return new BaseQuickAdapter<ClazzReportList, AutoBaseViewHolder>(R.layout.clazz_rv_item_report, lists) {
            private SimpleDateFormat mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());

            @Override
            protected void convert(AutoBaseViewHolder helper, ClazzReportList item) {
                Glide.with(mContext)
                        .load(item.getEvaluateTagUrl(mContext))
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_title, item.getEvaluateTagName());
                helper.setText(R.id.btn_score, item.getScore() > 0 ? "+" + item.getScore() : "" + item.getScore());
                QMUIRoundButton view = helper.getView(R.id.btn_score);
                QMUIRoundButtonDrawable bg = new QMUIRoundButtonDrawable();
                if (item.getScore() > 0) {
                    bg.setBgData(ColorStateList.valueOf(mContext.getResources().getColor(R.color.public_green)));
                } else {
                    bg.setBgData(ColorStateList.valueOf(mContext.getResources().getColor(R.color.public_red)));
                }
                QMUIViewHelper.setBackgroundKeepingPadding(view, bg);
                helper.setText(R.id.tv_content, "由" + item.getTeacherName() + "老师点评" + item.getStudentName());
                String start = TimeUtils.millis2String(item.getCreateTime(), mFormat);
                helper.setText(R.id.tv_time, start);
            }
        };

    }

}